<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/linux_perf/ftrace_importer.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('irqImport', function() {
    const lines = [
      ' kworker/u4:1-31907 (31907) [001] d.h3 14063.748288: ' +
        'irq_handler_entry: irq=27 name=arch_timer',
      ' kworker/u4:1-31907 (31907) [001] dNh3 14063.748384: ' +
        'irq_handler_exit: irq=27 ret=handled',
      ' kworker/u4:2-31908 (31908) [000] ..s3 14063.477231: ' +
        'softirq_entry: vec=9 [action=RCU]',
      ' kworker/u4:2-31908 (31908) [000] ..s3 14063.477246: ' +
        'softirq_exit: vec=9 [action=RCU]',
      ' RenderThread-2978  ( 2794) [002] dN.1 62828.421805: ' +
        'ipi_entry: (Rescheduling interrupts)',
      ' RenderThread-2978  ( 2794) [002] dN.1 62828.421809: ' +
        'ipi_exit: (Rescheduling interrupts)',
      ' RenderThread-2978  ( 2794) [002] dN.1 62829.421809: ' +
        'preempt_disable: caller=avc_lookup parent=avc_has_perm_noaudit',
      ' RenderThread-2978  ( 2794) [002] dN.1 62830.421809: ' +
         'preempt_enable: caller=avc_lookup parent=avc_has_perm_noaudit',
      ' kworker/u1:2-31908 (31908) [004] ..s3 14163.477231: ' +
         'irq_disable: caller=avc_lookup parent=avc_has_perm_noaudit',
      ' kworker/u1:2-31908 (31908) [004] ..s3 14163.477246: ' +
         'irq_enable: caller=avc_lookup parent=avc_has_perm_noaudit'
    ];
    const m = tr.c.TestUtils.newModelWithEvents([lines.join('\n')], {
      shiftWorldToZero: false
    });
    assert.isFalse(m.hasImportWarnings);

    let threads = m.getAllThreads();
    assert.strictEqual(threads.length, 5);

    threads = m.findAllThreadsNamed('irqs cpu 1');
    assert.strictEqual(threads.length, 1);
    assert.strictEqual(threads[0].sliceGroup.length, 1);

    threads = m.findAllThreadsNamed('softirq cpu 0');
    assert.strictEqual(threads.length, 1);
    assert.strictEqual(threads[0].sliceGroup.length, 1);

    threads = m.findAllThreadsNamed('irqs cpu 2');
    assert.strictEqual(threads.length, 1);
    assert.strictEqual(threads[0].sliceGroup.length, 1);

    threads = m.findAllThreadsNamed('preempt cpu 2');
    assert.strictEqual(threads.length, 1);
    assert.strictEqual(threads[0].sliceGroup.length, 1);

    threads = m.findAllThreadsNamed('irqoff cpu 4');
    assert.strictEqual(threads.length, 1);
    assert.strictEqual(threads[0].sliceGroup.length, 1);
  });
});
</script>
